import QtQuick 2.0

MouseArea{
    acceptedButtons: Qt.LeftButton | Qt.RightButton

    property int notOpen: 0
    property int opened: 1
    property int flaged: 2
    property int boomed: 3
    property int unknown: 4

    signal leftClicked()
    signal rightClicked()


    Image {
        id: name
        anchors.fill: parent
        anchors.margins: 5
        source: mineImg(mineState,mineData)
    }

    onClicked: {
        if (mouse.button === Qt.RightButton)
            rightClicked();
        else
            leftClicked();
    }
    function mineImg(mineState,mineData){
        var fileName = "";
        if(mineState === opened){
            switch(mineData){
            case -1:
                fileName = "qrc:UI/mine.png";
                break;
            case 0:
                fileName = "qrc:UI/zero.png";
                break;
            case 1:
                fileName = "qrc:UI/one.png";
                break;
            case 2:
                fileName = "qrc:UI/two.png";
                break;
            case 3:
                fileName = "qrc:UI/three.png";
                break;
            case 4:
                fileName = "qrc:UI/four.png";
                break;
            case 5:
                fileName = "qrc:UI/five.png";
                break;
            case 6:
                fileName = "qrc:UI/six.png";
                break;
            case 7:
                fileName = "qrc:UI/seven.png";
                break;
            case 8:
                fileName = "qrc:UI/eight.png";
                break;
            default:
                console.log("mineData Error:" + mineData);
                break;
            }
        }else if(mineState === boomed){
            fileName = "qrc:UI/boomed.png";
        }else if(mineState === boomed){
            fileName = "qrc:UI/flag.png";
        }else if(mineState === flaged){
            fileName = "qrc:UI/flag.png";
        }else if(mineState === unknown){
            fileName = "qrc:UI/unknown.png";
        }else {
            fileName = "qrc:UI/normal.png";
        }

        return fileName;
    }
}
